package ldh.im.base.service;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import ldh.common.PageResult;
import ldh.im.base.dao.ImGroupUserDao;
import ldh.im.base.pojo.ImGroupUser;
import ldh.im.base.pojo.where.ImGroupUserWhere;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: ldh
 * @date: 2024-03-21 10:36:17
*/
@Service("imGroupUserService")
public class ImGroupUserService {

	@Resource
	private ImGroupUserDao imGroupUserDao;
	
	@Transactional
	public ImGroupUser insert(ImGroupUser imGroupUser) {
		int n = imGroupUserDao.insert(imGroupUser);
		if (n != 1) {
			throw new RuntimeException("ImGroupUser insert error!");
		}
		return imGroupUser;
	}
	
	@Transactional
	public ImGroupUser insertSelective(ImGroupUser imGroupUser) {
		int n = imGroupUserDao.insert(imGroupUser);
		if (n != 1) {
			throw new RuntimeException("ImGroupUser insertSelective error!");
		}
		return imGroupUser;
	}

	@Transactional
	public ImGroupUser updateById(ImGroupUser imGroupUser) {
		int  n = imGroupUserDao.updateById(imGroupUser);
		if (n != 1) {
			throw new RuntimeException("ImGroupUser update error!");
		}
        return imGroupUser;
     }

	@Transactional
	public ImGroupUser updateNotNullById(ImGroupUser imGroupUser) {
		int  n = imGroupUserDao.updateNotNullById(imGroupUser);
		if (n != 1) {
			throw new RuntimeException("ImGroupUser update error!");
		}
        return imGroupUser;
     }


    @Transactional
    public void deleteById(Long id) {
		int n = imGroupUserDao.deleteById(id);
		if (n != 1) {
			throw new RuntimeException("ImGroupUser delete error!");
		}
    }

	@Transactional(readOnly = true)
	public ImGroupUser getByGroupIdAndUserId(Long groupId, String userId) {
		ImGroupUser imGroupUser = imGroupUserDao.getByGroupIdAndUserId(groupId, userId);
		return imGroupUser;
    }
    
	@Transactional(readOnly = true)
	public ImGroupUser getById(Long id) {
		ImGroupUser imGroupUser = imGroupUserDao.getById(id);
		return imGroupUser;
    }
    
	
	@Transactional(readOnly = true)
	public PageResult<ImGroupUser> findByImGroupUserWhere(ImGroupUserWhere imGroupUserWhere) {
		long total = imGroupUserDao.findTotalByImGroupUserWhere(imGroupUserWhere);
		List<ImGroupUser> imageList = new ArrayList<ImGroupUser>();
		if (total > 0) {
			imageList  = imGroupUserDao.findByImGroupUserWhere(imGroupUserWhere);
		}
		
		return new PageResult<ImGroupUser>(imGroupUserWhere, total, imageList);
	}
	
	
}
